<template>
  <el-row class="myrow">
    <el-col :span="20">
      <i class="el-icon-s-home myicon" style="font-size:20px"></i>
      {{ item.name }}
    </el-col>
    <el-col :span="2">
      <span>{{ item.manager }}</span>
    </el-col>
    <el-col :span="2">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link mydrodown">
          操作<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown" class="myDropdownMenu">
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item command="see" v-if="!item.isTop"
            >查看部门</el-dropdown-item
          >
          <el-dropdown-item command="del" v-if="!item.isTop"
            >删除部门</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { deleteDepartments } from '../../../api/departments'
export default {
  props: ['item'],
  created () {},
  methods: {
    async handleCommand (command) {
      if (command === 'del') {
        try {
          await this.$confirm('确定删除该部门吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          await deleteDepartments(this.item.id)
          this.$emit('refreshdata')
          this.$message({
            type: 'info',
            message: '删除成功'
          })
        } catch {
          return
        }
      }
      if (command === 'add') {
        this.$emit('showDialog')
        this.$emit('curren', this.item)
      }
      if (command === 'see') {
        this.$emit('getDepartments', this.item.id)
      }
    }
  }
}
</script>

<style lang="scss" coped></style>
